<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script src="jquery-1.3.2.js">
</script>
<script>

var campos = 0;

function appendText()
{
	this.campos++; 
	var txt1 = "";
	txt1 	+= "Campo: <input name='campo["+this.campos+"]' type='text' />";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	txt1 	+= "Tipo: <select name='tipo["+this.campos+"]' id='tipo'>";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	txt1 	+= "<option value='1'>Texto (curto)</option>";
	txt1 	+= "<option value='2'>Texto (longo)</option>";
	txt1 	+= "<option value='3'>Data</option>";
	txt1 	+= "<option value='9'>Hora</option>";
	txt1 	+= "<option value='4'>Telefone</option>";
	txt1 	+= "<option value='5'>CPF</option>";
	txt1 	+= "<option value='6'>Arquivo</option>";
	txt1 	+= "<option value='7'>Email</option>";
	txt1 	+= "</select>";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	txt1 	+= "<label>Obrigatório:</label>";
	txt1 	+= "<label><input type='radio' name='obrigatorio["+this.campos+"]' value='1' id='obrigatorio_0'>Sim</label>";
	txt1 	+= "<label><input type='radio' name='obrigatorio["+this.campos+"]' value='0' id='obrigatorio_1'>Não</label>";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	txt1 	+= "<label>Data Grid:</label>";
	txt1 	+= "<label><input type='checkbox' name='grid["+this.campos+"]' id='grid'></label>";
    txt1 	+= "<br/><br/>";
 	// Create text with DOM
	$("#content-1_form-1").append( txt1 );        // Append new elements
}

function appendRel()
{
	this.campos++; 
	var txt1 = "";
	txt1 	+= "Entidade: <input name='entidaderel["+this.campos+"]' type='text' />";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	txt1 	+= "Campo: <input name='campo["+this.campos+"]' type='text' />";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	txt1 	+= "<input name='tipo["+this.campos+"]' value='8' type='text' />";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	txt1 	+= "<label><input type='radio' name='obrigatorio["+this.campos+"]' value='1' id='obrigatorio_0'>Sim</label>";
	txt1 	+= "<label><input type='radio' name='obrigatorio["+this.campos+"]' value='2' id='obrigatorio_1'>Não</label>";
	txt1 	+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    txt1 	+= "<br/><br/>";
 	// Create text with DOM
	$("#content-1_form-1").append( txt1 );        // Append new elements
}
</script>
</head>
    <body>
    
    <br />
    <button onclick="appendText()">Novo ítem</button>
    <button onclick="appendRel()">Novo Relacionamento</button>
    <br />
    <hr />
    
	<div id="content-1">
    	<form id="form-1" action="index.php?passo=1" method="post">
        	
            Entidade: <input name='entidade' type='text' />
            Titulo: <input name='titulo' type='text' />
            Layout adm: <input name='layout_adm' type='text' />
            <br />
            Local Output: <input name='output' type='text' />
            
            
            <br />
            <br />
        	<span id="content-1_form-1"></span>
        	<input name="passo1" type="submit" value="Passo 1" />
        </form>
    </div>
    
    
    <?php
	
	
		
		if( $_POST ){
			
			$entidade = strtolower( $_POST["entidade"] );
						
			if( $_GET["passo"] == 1 ){
				
				$layout_adm = $_POST["layout_adm"];
				
				if( empty( $_POST["output"] ) )
					$output = "output/";
				else
					$output = $_POST["output"]."/";
				//exit;
				/// Gerando CONTROLLER ---------------------------------------------------------------------
				$src = null;
				include("content/controller.php");
				
				if( !file_exists( $output . "app" ) )
					mkdir( $output . "app" , 0777 );
					
				if( !file_exists( $output . "/app/controllers" ) )	
					mkdir( $output . "app/controllers" , 0777 );
				
				$fp_controller = fopen( $output . "app/controllers/" . $entidade . "Controller.php" , "w+" );
				$_controller = fwrite( $fp_controller , $src );
				fclose( $fp_controller );
				
				
				/// Gerando MODEL --------------------------------------------------------------------------
				$src = null;
				include("content/model.php");
				
				if( !file_exists( $output . "app" ) )
					mkdir( $output . "app" , 0777 );
					
				if( !file_exists( $output . "app/models" ) )	
					mkdir( $output . "app/models" , 0777 );
				
				$fp_model = fopen( $output . "app/models/" . $entidade . "Model.php" , "w+" );
				$_model = fwrite( $fp_model , $src );
				fclose( $fp_model );
				
				
				/// Gerando VIEW --------------------------------------------------------------------------
				$src = null;
				include("content/view.php");
			
				if( !file_exists( $output . "app" ) )
					mkdir( $output . "app" , 0777 );
					
				if( !file_exists( $output . "/app/views" ) )	
					mkdir( $output . "app/views" , 0777 );
				
				if( !file_exists( $output . "app/views/" . $entidade ) )	
					mkdir( $output . "app/views/" . $entidade , 0777 );
				
				
				$fp_view = fopen( $output . "app/views/" . $entidade ."/admin.phtml" , "w+" );
				$_view = fwrite( $fp_view , $src );
				fclose( $fp_view );
				
				
				/// Gerando VALIDACAO --------------------------------------------------------------------------
				$src = null;
				include("content/validacao.php");
				
				if( !file_exists( $output . "web-files" ) )
					mkdir( $output . "web-files" , 0777 );
					
				
				if( !file_exists( $output . "/web-files/validacao" ) )	
					mkdir( $output . "/web-files/validacao"  , 0777 );
				
				
				$fp_validacao = fopen( $output . "/web-files/validacao/" . $entidade ."Validacao.js" , "w+" );
				$_validacao = fwrite( $fp_validacao , $src );
				fclose( $fp_validacao );
				
				
			}
			
		}
	
	?>
    
    
    
</body>
</html>










